package com.manytory.torylotto.data;

import android.app.Application;
import android.app.Service;
import android.content.SharedPreferences;

public class ToryLotto_App extends Application{
	final private String ToryLotto_SharedPreferences = "ToryLotto_SharedPreferences";
	private static SharedPreferences.Editor PreEditor;
	
	final private static String ToryLotto_Auth_State = "ToryLotto_Auth_State";
	final private static String ToryLotto_PushKey = "ToryLotto_PushKey";
	final private static String ToryLotto_Now_TH = "ToryLotto_Now_TH";
	final private static String ToryLotto_Now_Sum_Money = "ToryLotto_Now_Sum_Money";
	final private static String ToryLotto_Now_Date = "ToryLotto_Now_Date";
	
	public static int nAuthState = 0;
	public static String strPushKey = "";
	
	public static String strNowTH = "";
	public static String strNowSumMoney = "";
	public static String strNowDate = "";
	
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		loadPreferences();
	}
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
	}

	public void loadPreferences() {
		SharedPreferences Preferences = getSharedPreferences(ToryLotto_SharedPreferences, Service.MODE_PRIVATE);
		PreEditor = Preferences.edit();
		
		nAuthState = Preferences.getInt(ToryLotto_Auth_State, 0);
		strPushKey = Preferences.getString(ToryLotto_PushKey, "");
		
		strNowTH = Preferences.getString(ToryLotto_Now_TH, "");
		strNowSumMoney = Preferences.getString(ToryLotto_Now_Sum_Money, "");
		strNowDate = Preferences.getString(ToryLotto_Now_Date, "");
	}
	
	public void saveAuthStatePreferences(int devauthFlag) {
		nAuthState = devauthFlag;
		PreEditor.putInt(ToryLotto_Auth_State, nAuthState);
		PreEditor.commit();
	}
	
	public void savePushKeyPreferences(String strkey) {
		strPushKey = strkey;
		PreEditor.putString(ToryLotto_PushKey, strkey);
		PreEditor.commit();
	}
	
	public void saveNowTHPreferences(String strTH) {
		strNowTH = strTH;
		PreEditor.putString(ToryLotto_Now_TH, strTH);
		PreEditor.commit();
	}
	
	public void saveNowSumMoneyPreferences(String strMoney) {
		strNowSumMoney = strMoney;
		PreEditor.putString(ToryLotto_Now_Sum_Money, strMoney);
		PreEditor.commit();
	}
	
	public void saveNowDatePreferences(String strDate) {
		strNowDate = strDate;
		PreEditor.putString(ToryLotto_Now_Date, strDate);
		PreEditor.commit();
	}
}
